package com.edu.exam.entity.curriculum.questionbank;

import com.edu.exam.enums.curriculum.InterferenceEffect;
import com.edu.exam.enums.curriculum.InterferenceType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 多选题选项实体类
 * 所属模块：B-02 题库管理模块
 * 对应数据库表：mcq_options
 *
 * 管理多选题的选项信息，包括选项内容、正确性标识、序号、解析说明以及使用统计数据。
 * 支持选项的完整生命周期管理，包括选项的增删改查、干扰性评估和使用统计。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Comment("多选题选项表")
@SQLDelete(sql = "UPDATE mcq_options SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class MultipleChoiceOption {

    /**
     * 选项唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 所属多选题ID
     */
    @NotNull(message = "多选题ID不能为空")
    @Column(name = "question_id", nullable = false)
    private Long questionId;

    /**
     * 选项内容
     */
    @NotBlank(message = "选项内容不能为空")
    @Size(max = 1000, message = "选项内容长度不能超过1000个字符")
    @Column(name = "content", nullable = false, length = 1000)
    private String content;

    /**
     * 是否为正确答案
     */
    @NotNull(message = "正确性标识不能为空")
    @Column(name = "is_correct", nullable = false)
    @Builder.Default
    private Boolean isCorrect = false;

    /**
     * 选项序号，从1开始
     */
    @NotNull(message = "选项序号不能为空")
    @Column(name = "option_order", nullable = false)
    private Integer optionOrder;

    /**
     * 选项解析说明
     */
    @Column(name = "explanation", columnDefinition = "TEXT")
    private String explanation;

    /**
     * 干扰项类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "interference_type", length = 50)
    private InterferenceType interferenceType;

    /**
     * 被选择次数统计
     */
    @NotNull(message = "选择次数不能为空")
    @Column(name = "select_count", nullable = false)
    @Builder.Default
    private Integer selectCount = 0;

    /**
     * 正确选择次数统计
     */
    @NotNull(message = "正确选择次数不能为空")
    @Column(name = "correct_select_count", nullable = false)
    @Builder.Default
    private Integer correctSelectCount = 0;

    /**
     * 创建时间
     */
    @NotNull(message = "创建时间不能为空")
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @NotNull(message = "更新时间不能为空")
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标记
     */
    @NotNull(message = "删除标记不能为空")
    @Column(name = "is_deleted", nullable = false)
    @Builder.Default
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    @PrePersist
    protected void onCreate() {
        LocalDateTime now = LocalDateTime.now();
        this.createTime = now;
        this.updateTime = now;
    }

    @PreUpdate
    protected void onUpdate() {
        this.updateTime = LocalDateTime.now();
    }

    
}